package mysql

import (
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"github.com/jmoiron/sqlx"
	. "my-crawler/config"
)

var Db *sqlx.DB

func init() {
	config := LoadConfig()
	//database, err := sqlx.Open("数据库类型", "用户名:密码@tcp(地址:端口)/数据库名")
	mysqlDatabase, err := sqlx.Open("mysql",
		config.MySqlConn.User+":"+config.MySqlConn.Password+"@tcp("+config.MySqlConn.Address+":"+config.MySqlConn.Port+")/"+config.MySqlConn.DbName+"?charset=utf8")
	if err != nil {
		fmt.Println("open mysql failed,", err)
		return
	}
	Db = mysqlDatabase
}
